home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / nwrip.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  5KB  |  153 lines

  1. Unit NwRIP;
  2.  
  3. { NwTP Version 0.6, Copyright 1993,1994 R. Spronk
  4.  
  5.   WARNING: Test your program thoroughly if you're using nwRip functions.
  6.   ----------------------------------------------------------------------
  7.  
  8.   Using the RIP functionality the wrong way may very well result in
  9.   aborting servers ! (no kidding.)
  10.  
  11.   As far as I know the diagnostic RIP function(s) included in this unit
  12.   are perfectly safe to use.
  13.  
  14.   Based on:
  15.  
  16.   -GETALL, written in C by Barry Lagerweij of 2:2802/110.2
  17.    posted in the Fido NOVELL area on Tue 7 Sep 93  0:36.
  18.   -GETRIP, written in C by Koos van den Hout of 2:500/101.11012
  19.    last updated 8 Feb 93 }
  20.  
  21. INTERFACE
  22.  
  23. Uses nwMisc,nwIPX;
  24.  
  25. CONST ECB_COUNT=10;
  26. { assumption : 10 receiveECBs are used, which means a max of 500 networks }
  27.  
  28. { Type definitions for RIP request/response structures}
  29. type TRIPentry=record
  30.                network:TnetworkAddress;
  31.                hops   :word;
  32.                ticks  :word;
  33.                end;
  34.  
  35.      TRIPanswerPacket=record
  36.                       operation:word;
  37.                       entry    :array[1..50] of TRIPEntry;
  38.                       end;
  39.  
  40.      TRIPinfo=array[1..50*ECB_COUNT] of record
  41.                                         address:TnetworkAddress;
  42.                                         hops   :byte;
  43.                                         Ticks  :word;
  44.                                         end;
  45.  
  46. Function GetAllNetworks(SegmentNetworkAddress:TnetworkAddress;
  47.                     Var NetInfo:TRIPinfo):word;
  48. {SegmentNetworkAddress: The target network whose routers
  49.                         will be queried. Set to all zeroes (00 00 00 00)
  50.                         if querying your own segment.
  51.  NetInfo : the buffer where the network-info is stored.
  52.  Returns : the number of known networks.
  53.  
  54.  Assumed is that IPXInitialize is already called. }
  55.  
  56. IMPLEMENTATION {===========================================================}
  57.  
  58. Function GetAllNetworks(SegmentNetworkAddress:TnetworkAddress;
  59.                     Var NetInfo:TRIPinfo):word;
  60. Var
  61.     RIPrequest      :TRIPanswerPacket;
  62.     RIPanswer       :array[1..ECB_COUNT] of TRIPanswerPacket;
  63.     RequestEcb      :Tecb;
  64.     RequestIPXheader:TipxHeader;
  65.     ReplyECB        :array[1..ECB_COUNT] of Tecb;
  66.     ReplyIPX        :array[1..ECB_COUNT] of TipxHeader;
  67.     Target          :TinternetworkAddress;
  68.     Sourcesocket    :word;
  69.     RIPsocket       :word;
  70.  
  71.     NumberOfNets    :word;
  72.     cnt             :word;
  73.     n               :word;
  74.     RoutableNetworks:word;
  75.     timer1,timer2:word;
  76.  
  77. Begin
  78. RIPsocket:=$0453;
  79.  
  80. SourceSocket:=0;
  81. { open socket for receiving the RIP packets }
  82. IF NOT IPXopenSocket(SourceSocket,SHORT_LIVED_SOCKET)
  83.  then begin
  84.       result:=nwIPX.result;
  85.       GetAllnetworks:=0;
  86.       exit;
  87.       end;
  88.  
  89. {set-up sendpacket }
  90. target.net:=SegMentNetworkAddress;
  91. fillchar(target.node,6,#$FF); { all nodes i.e. all routers }
  92. target.socket:=RIPsocket;
  93. IPXsetUpSendECB(NIL,SourceSocket,target,@RIPrequest,SizeOf(RIPrequest),
  94.                 RequestIPXheader, RequestECB);
  95. RequestIPXheader.packetType := 1;
  96.  { 1=RIP / Any value will work/ type seems to be ignored by Routers
  97.            as long as socket is OK.  }
  98.  
  99. { set-up the RIP request }
  100. FillChar(RIPrequest,SizeOf(RIPrequest),#$FF);
  101. RIPrequest.operation := $0100;  { hi-lo, RIP request }
  102. FillChar(RIPanswer,SizeOf(RIPanswer),#$00);
  103.  
  104.  
  105. { set-up the receive ECBs }
  106. for n:=1 to ECB_COUNT
  107.  do begin
  108.     IPXsetupListenECB(NIL,SourceSocket,
  109.                       @RIPanswer[n],SizeOf(TRIPanswerPacket),
  110.                       ReplyIpx[n],ReplyECB[n]);
  111.     IPXListenForPacket(ReplyECB[n]);
  112.     end;
  113.  
  114. { send the RIP request }
  115. IPXSendPacket(RequestECB);
  116.  
  117. { wait a while for answers }
  118. IPXgetIntervalMarker(timer1);
  119. REPEAT
  120.  IPXrelinquishcontrol;
  121.  IPXGetIntervalMarker(timer2);
  122. UNTIL abs(timer2-timer1)>20;
  123.  
  124. NumberOfNets := 0;
  125.  
  126. { check all possible RIP responses, and fill the tables }
  127. for n:=1 to ECB_COUNT
  128.  do if (ReplyECB[n].INuseFlag=0) and (RIPanswer[n].operation=$0200)
  129.      then begin
  130.           RoutableNetworks:=(swap(ReplyIPX[n].Length)-32) DIV SizeOf(TRIPentry);
  131.           for cnt:=1 to RoutableNetworks
  132.            do begin
  133.               inc(NumberOfNets);
  134.               With NetInfo[NumberOfNets]
  135.                do begin
  136.                   Address:=RIPanswer[n].entry[cnt].network;
  137.                   hops:=swap(RIPanswer[n].entry[cnt].hops);
  138.                   ticks:=swap(RIPanswer[n].Entry[cnt].ticks);
  139.                   end;
  140.               end;
  141.           end
  142.      else IPXcancelEvent(ReplyECB[n]);
  143.  
  144. { our socket is no longer needed }
  145. IPXCloseSocket(SourceSocket);
  146.  
  147. { return the number of networks we found }
  148. GetAllNetworks:=NumberOfNets;
  149. end;
  150.  
  151.  
  152. end.
  153.